package com.mall.cms.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mall.cms.mapper.SubjectMapper;
import com.mall.cms.service.SubjectService;
import com.mall.model.domain.cms.Subject;
import com.mall.utils.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SubjectServiceImpl extends ServiceImpl<SubjectMapper, Subject> implements SubjectService {

    @Autowired
    private SubjectMapper subjectMapper;

    @Override
    public PageResult getSubject(String keyword, Integer pageNum, Integer pageSize) {
        Page<Subject> page = new Page<>(pageNum,pageSize);
        LambdaQueryWrapper<Subject> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.like(keyword!=null,Subject::getCategoryName,keyword);
        Page<Subject> pageInfo = subjectMapper.selectPage(page, queryWrapper);
        PageResult pageResult = PageResult.init(pageInfo);
        return pageResult;
    }
}
